<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改数据集市')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content" >
        <h4 class="form-header h4" onclick="choseRely()" style="cursor:pointer ">依赖对象 <i class="glyphicon glyphicon-plus"></i></h4>
        <div class="row">
            <table class="table table-bordered" style="width: 70%;margin: 0 auto">
                <colgroup>
                    <col width="10%">
                    <col width="20%">
                    <col width="20%">
                    <col width="20%">
                    <col width="20%">
                    <col width="10%">
                </colgroup>
                <thead>
                <tr>
                    <th>ID</th>
                    <th>编码</th>
                    <th>名称</th>
                    <th>关联表</th>
                    <th>关联字段</th>
                    <th></th>
                </tr>
                </thead>
                <tbody id="relyTbody" >
                <tr th:each="item:${relyList}">
                    <td th:text="${item.idRelyFk}"></td>
                    <td th:text="${item.cdRelyTb}"></td>
                    <td th:text="${item.des}"></td>
                    <td th:text="${item.cdTbJoin}"></td>
                    <td th:text="${item.idPubfldJoin}"></td>
                    <td>
                        <a class="btn btn-danger btn-xs " href="javascript:void(0)" th:onclick="deleteRely([[${item.idDrawDmRely}]])"><i class="fa fa-edit"></i>删除</a>
                        <a class="btn btn-info btn-xs " href="javascript:void(0)" th:onclick="queryFlds([[${item.des}]],[[${item.cdRelyTb}]])"><i class="fa fa-edit"></i>字段</a>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
        <h4 class="form-header h4" onclick="choseFld()" style="cursor:pointer ">字段选择 <i class="glyphicon glyphicon-plus"></i></h4>
        <div class="row">
            <table class="table table-bordered" style="width: 70%;margin: 0 auto">
                <colgroup>
                    <col width="40%">
                    <col width="40%">
                    <col width="20%">
                </colgroup>
                <thead>
                <tr>
                    <th>编码</th>
                    <th>名称</th>
                    <th></th>
                </tr>
                </thead>
                <tbody id="fildLIst" >
                <tr th:each="item:${fldList}">
                    <td th:text="${item.idPubfld}"></td>
                    <td th:text="${item.naPubfld}"></td>
                    <td><a class="btn btn-danger btn-xs " href="javascript:void(0)" th:onclick="deleteFld([[${item.idDrawDmFld}]])"><i class="fa fa-edit"></i>删除</a></td>
                </tr>
                </tbody>
            </table>
        </div>
        <h4 class="form-header h4" style="color: #0a2730">配置信息</h4>
        <form class="form-horizontal m" id="form-dm-edit" th:object="${etlDrawDm}">
            <input name="idDrawDm" th:field="*{idDrawDm}" type="hidden" id="idDrawDm">
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">指标：</label>
                        <div class="col-sm-8">
                            <input name="naIndex" id="naIndex" th:field="*{naIndex}" class="form-control" type="text" disabled>
                        </div>
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">可建表标志：</label>
                        <div class="col-sm-8">
                            <label class="toggle-switch switch-solid">
                                <input type="checkbox" name="fgTb" th:checked="*{fgTb == 1 ? true : false}" disabled>
                                <span></span>
                            </label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">度量：</label>
                        <div class="col-sm-8">
                            <input name="sqlValue" th:field="*{sqlValue}" class="form-control" type="text">
                        </div>
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">启用标志：</label>
                        <div class="col-sm-8">
                            <label class="toggle-switch switch-solid">
                                <input type="checkbox" id="fgAct" th:checked="*{fgAct == 1 ? true : false}"/>
                                <span></span>
                            </label>
                        </div>
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">默认过滤：</label>
                        <div class="col-sm-8">
                            <label class="toggle-switch switch-solid">
                                <input type="checkbox" id="fgDefFilter" th:checked="*{fgDefFilter == 1 ? true : false}"/>
                                <span></span>
                            </label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">计算公式：</label>
                <div class="col-sm-8">
                    <input name="formu" th:field="*{formu}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label">过滤条件</label>
                <div class="col-sm-8">
                    <textarea name="sqlWhere" class="form-control" rows="5">[[*{sqlWhere}]]</textarea>
                </div>
            </div>
        </form>
        <div class="row">
            <div class="col-sm-offset-5 col-sm-10">
                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
            </div>
        </div>
    </div>

    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "etl/dm";
        $("#form-dm-edit").validate({
            focusCleanup: true
        });
        function choseRely(){
            var options = {
                title:"添加["+$("#naIndex").val()+"]依赖数据",
                width: "600",
                height: "600",
                url: prefix+"/addRely/"+$("#idDrawDm").val(),
                callBack: reloadRely
            };
            $.modal.openOptions(options);
            //$.modal.open("添加["+$("#naIndex").val()+"]依赖数据",prefix+"/addRely/"+$("#idDrawDm").val(),400,600);
        }
        function choseFld(){
            var options = {
                title:"添加["+$("#naIndex").val()+"]维度字段",
                width: "500",
                height: "600",
                url: prefix+"/addFld/"+$("#idDrawDm").val(),
                callBack: reloadFld
            };
            $.modal.openOptions(options);
        }
        function reloadRely(index, layero) {
            var iframeWin = layero.find('iframe')[0];
            iframeWin.contentWindow.submitHandler(index, layero);
            location.reload();
        }
        function reloadFld(index, layero) {
            var iframeWin = layero.find('iframe')[0];
            iframeWin.contentWindow.submitHandler(index, layero);
            location.reload();
        }
        function submitHandler() {
            debugger;
            var fgAct,fgDefFilter;
            if($("#fgDefFilter").is(":checked")) {
                fgDefFilter = 1;
            } else {
                fgDefFilter = 0;
            }
            if($("#fgAct").is(":checked")) {
                fgAct = 1;
            } else {
                fgAct = 0;
            }
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-dm-edit').serialize()+"&fgDefFilter="+fgDefFilter+"&fgAct="+fgAct);
            }
            closeItem();
        }
        function deleteRely(ele) {
            $.ajax({
                url: prefix+"/deleteRely/"+ele,
                cache: false,
                type: 'GET',
                dataType: 'json',
                success: function (result) {
                    if(result.code=="0") {
                        location.reload();
                    }
                }
            });
        }

        function deleteFld(ele) {
            $.ajax({
                url: prefix+"/deleteFld/"+ele,
                type: 'GET',
                dataType: 'json',
                success: function (result) {
                    if(result.code=="0") {
                        location.reload();
                    }
                }
            });
        }
        function queryFlds(name,table) {
            var options = {
                title:"仓库["+name+"]字段",
                width: "900",
                height: "700",
                url: "/md/med/fld/queryByTb?cdTb="+table
            };
            $.modal.openOptions(options);
        }
        $("input[name='dtSysCre']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='dtSysModi']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>